#include <iostream>
#include <vector>

/**
 * 邻接表使用
 */
int main(){
    int n,m;
    std::cin >> n >> m;

    std::vector<std::vector<int>> graph(n, std::vector<int>());

    for(int i=0; i<m; i++){
        int a,x,y;
        std::cin >> a >> x >> y;

        if(a==0){
            graph[x].push_back(y);
        }else{
            graph[x].push_back(y);
            graph[y].push_back(x);
        }
    }

    for(int i=0; i< graph.size(); i++){
        std::cout << i << ": ";
        for(int j=graph[i].size()-1;j>=0; j--){
            std::cout << graph[i][j] << " ";
        }
        std::cout << "\n";
    }


    return 0;
}